<?php
declare (strict_types = 1);

namespace app\model\communal;

use app\model\concern\AmisTrait;
use think\db\Query;
use think\model\Pivot;
use think\model\relation\BelongsTo;

class ScaleMultiExpertModel extends Pivot
{
    use AmisTrait;

    /**
     * 数据库配置
     *
     * @var string
     */
    protected $connection = 'communal';

    /**
     * 主键
     *
     * @var string
     */
    protected $pk = 'id';

    /**
     * 表名
     *
     * @var string
     */
    protected $table = '70200_scale_multi_expert';

    /**
     * 自动时间戳
     *
     * @var bool
     */
    protected $autoWriteTimestamp = true;

    /**
     * 时间字段设置
     *
     * @var string
     */
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';

    /**
     * 展示字段名
     *
     * @var string[]
     */
    public static $column = [
        'id', 'admin_id', 'scale_multi_id', 'expert_id', 'amount', 'state', 'created_at'
    ];

    /**
     * 搜索字段名
     *
     * @var string[]
     */
    public static $searchColumn = [
        'id', 'scale_multi_id', 'expert_id', 'state', 'createtime'
    ];

    /**
     * 新增字段
     *
     * @var string[]
     */
    public static $saveColumn = [
        'scale_multi_id', 'expert_id', 'amount',
    ];

    /**
     * 更新字段
     *
     * @var string[]
     */
    public static $updateColumn = [
        'id', 'scale_multi_id', 'expert_id', 'amount',
    ];

    /**
     * @var string[]
     */
    public static $itemColumn = [
        'id', 'expert_id', 'state'
    ];

    /**
     * @return BelongsTo
     */
    public function belongsMulti()
    {
        return $this->belongsTo(ScaleMultiModel::class, 'scale_multi_id', 'id')
            ->bind([
                'multi_name' => 'name',
            ]);
    }

    /**
     * @return BelongsTo
     */
    public function belongsExpert()
    {
        return $this->belongsTo(UserExpertModel::class, 'expert_id', 'id')
            ->bind([
                'expert_avatar' => 'avatar',
                'expert_name' => 'name',
                'expert_title' => 'title',
                'expert_expert' => 'expert',
            ]);
    }
}
